//package com.corpgovernment.organization.service;
//
//import com.actionsoft.bpms.api.OpenApiClient;
//import com.actionsoft.sdk.service.response.ListMapResponse;
//import com.corpgovernment.organization.config.OrgClientConfig;
//import org.springframework.util.CollectionUtils;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.RecursiveTask;
//
///**
// * @ClassName: PeopleTask
// * @description: TODO
// * @author: zdwang
// * @date: Created in 14:22 2019/7/29
// * @Version: 1.0
// **/
//public class PeopleTask extends RecursiveTask<List<Map<String, Object>>> {
//    private final String GET_USERS_BYDPID = "org.users.get.department";
//    private static final int packet = 1000;
//
//    private List<String> deptIds;
//
//    private OpenApiClient client;
//
//    private int start;
//
//    private int end;
//
//    public PeopleTask(List<String> deptIds, OpenApiClient client, int start, int end) {
//        this.deptIds = deptIds;
//        this.client = client;
//        this.start = start;
//        this.end = end;
//    }
//
//    @Override
//    protected List<Map<String, Object>> compute() {
//        if ((end - start) < packet) {
//            List<Map<String, Object>> result = new ArrayList<>();
//            for (int i = start; i <= end; i++) {
//                String deptId = deptIds.get(i);
//                Map param = new HashMap<>();
//                param.put("departmentId", deptId);
//                ListMapResponse r = client.exec(GET_USERS_BYDPID, param, ListMapResponse.class);
//                List<Map<String, Object>> data = r.getData();
//                result.addAll(data);
//            }
//            return result;
//        } else {
//            int mid = (end + start) >> 1;
//            PeopleTask leftTask = new PeopleTask(deptIds, client, start, mid);
//            PeopleTask rightTask = new PeopleTask(deptIds, client, mid + 1, end);
//            invokeAll(leftTask, rightTask);
//            List<Map<String, Object>> left = leftTask.join();
//            List<Map<String, Object>> right = rightTask.join();
//            left = left == null ? new ArrayList<>() : left;
//            if (!CollectionUtils.isEmpty(right)) left.addAll(right);
//            return left;
//        }
//    }
//}